<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<?php
if (!isset($update)) {
    ?>
    <div id="post-text-form" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-header">
    	<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    	<h3 id="myModalLabel">Post Text</h3>
        </div>
	<?php
    }
    $form = $this->beginWidget('CActiveForm', array(
	'id' => 'post-form',
	'enableAjaxValidation' => FALSE,
	'enableClientValidation' => true,
	'clientOptions' => array(
	    'validateOnSubmit' => true
	),
	'htmlOptions' => array(
	    'class' => 'form-horizontal',
	    'enctype' => "multipart/form-data"
	)
    ));
    ?>
    <div class="<?php
    if (!isset($update))
	echo 'modal-body';
    else
	echo 'edit-post-body';
    ?>">
	<p>
	    <?php
	    echo $form->label($model, 'title');
	    echo $form->textField($model, 'title', array('class' => 'input-post'));
	    echo $form->error($model, 'title');

	    echo $form->label($model, 'content');
	    echo $form->textArea($model, 'content', array('class' => 'input-post'));
	    echo $form->error($model, 'content');
	    ?>
	    <?php
	    if (!isset($update)) {
		?>	

    	    <br>
    	    <br>
    	    <select class="select-type-addition">
    		<option value="">Add Content</option>
    		<option value="photo">Photo</option>
    		<option value="audio">Audio</option>
    		<option value="video">Video</option>
    	    </select>
    	    <a href="javascript:void(0)" class="btn btn-primary btn-add-addition">Add</a>	    	    
    	    <span class='wrap-upload-addition'>
    	    </span>
		<?php
	    } else {
		?>
    	    <br>
    	    <br>
    	<div id="wrapper-photo-edit">
    	    <label>Photo</label>
		<?php
		//show attachment	
		if (isset($attachment['photo'])) {
		    foreach ($attachment['photo'] as $photo) {
			echo '<div class="wrapper-photo-edit-inner">
				<a title="Delete this Image" class="btn-delete-img delete-file" href="javascript:void(0)" post-id="' . $model->post_id . '" file-name="' . $photo . '" file-type="photo">
				<i class="icon-remove"></i></a>
				<img src="' . ImageHelper::thumb(64, 64, 'photo' . DIRECTORY_SEPARATOR . $photo) . '" />
			    </div>';
		    }
		    echo '<div class="clear"></div>';
		    $inputPhoto = 5 - count($attachment['photo']);
		    if ($inputPhoto > 0) {
			if ($inputPhoto !== 5)
			    echo '<br>More photo<br>';
			for ($i = 0; $i < $inputPhoto; $i++) {
			    echo "<input type='file' name='photo[]' accept='image/*'/><br>";
			}
		    }
		}
		?>
    	</div>

    	<br>    	

    	<div id="wrapper-audio-edit">
    	    <label>Audio</label>	  
		<?php
		$audio = $model->getAudio();
		if ($audio) {
		    echo '<div id="div-audio">' . $audio . '</div>';
		    echo '<a id="remove-audio" href="javascript:void(0)" class="delete-file"   post-id="' . $model->post_id . '" file-name="' . $attachment['audio'] . '" file-type="audio"><i class="icon-remove"></i> Delete</a>';
		} else {
		    echo "<input type='file' name='audio' accept='audio/*'/><br>";
		}
		?>	    			    		


    	</div>    	
    	<br>
    	<div id="wrapper-video-edit">
    	    <label>Video</label>	  
		<?php
		$video = $model->getVideo();
		if ($video) {
		    echo '<div id="div-video">' . $video . '</div>';
		    echo '<a id="remove-video" href="javascript:void(0)" class="delete-file"   post-id="' . $model->post_id . '" file-name="' . $attachment['video']['upload'] . '" file-type="video"><i class="icon-remove"></i> Delete</a>';
		} else {
		    echo "<input type='file' name='video' accept='video/*'/><br>";
		}
		?>		
    	</div>
    	<br>    	
	    <?php
	}
	?>
	<?php
	echo $form->label($model, 'tags');
	echo $form->textField($model, 'tags', array('class' => 'input-post'));
	echo $form->error($model, 'tags');
//
//	    echo $form->label($model, 'is_private');
//	    echo $form->dropDownList($model, 'is_private', array('0' => 'Public', '1' => 'Private'), array('class' => 'input-post'));
//	    echo $form->error($model, 'is_private');
	?>
	<input type='hidden' value="<?php echo Posts::TYPE_TEXT ?>" name="Posts[post_type]"/>
	</p>
    </div>
    <div class="modal-footer">
	<?php
	if (!isset($update)) {
	    ?>
    	<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
	<?php } ?>
	<input type="submit" class="btn btn-info" value="Create" name='posting'/>
    </div>
    <?php
    $this->endWidget();
    ?>
    <?php
    if (!isset($update)) {
	?>
    </div>
    <?php
}

